#include "MioPath.h"
#include "MioMacro.h"

namespace mio
{
#if _WIN_
	class Path_Win : public Path {
	public:
		std::string docPath(const std::string &file);
		std::string appPath(const std::string &file);
		bool isFileExist(const std::string &file);
	};

	std::string Path_Win::docPath(const std::string &file)
	{
		std::string path = "../../assets/";
		return path + file;
	}
	std::string Path_Win::appPath(const std::string &file)
	{
		std::string path = "../../assets/";
		return path + file;
	}
	bool Path_Win::isFileExist(const std::string &file) { return false; }

	Path& getPath()
	{
		static Path_Win p;
		return p;
	}
#elif _ANDROID_
	class Path_Android : public Path {
	public:
		std::string docPath(const std::string &file);
		std::string appPath(const std::string &file);

		bool isFileExist(const std::string &file);
	};
	Path& getPath()
	{
		static Path_Android path;
		return path;
	}
	std::string Path_Android::docPath(const std::string &file)
	{
		std::string path = "/mnt/sdcard/sage/";
		return path + file;
	}

	std::string Path_Android::appPath(const std::string &file)
	{
		std::string path = "/mnt/sdcard/sage/";
		return path + file;
	}

	bool Path_Android::isFileExist(const std::string &file)
	{
		//TODO
		return false;
	}

#endif

	std::string Path::docPath(const char *name, const char *ext)
	{
		std::string file(name);
		file += ".";
		file += ext;
		return docPath(file);
	}
	std::string Path::docPath(const char *file)
	{
		std::string filestr(file);
		return docPath(filestr);
	}

	std::string Path::appPath(const char *name, const char *ext)
	{
		std::string file(name);
		file += ".";
		file += ext;
		return this->appPath(file);
	}
	std::string Path::appPath(const char *file)
	{
		std::string filestr(file);
		return this->appPath(filestr);
	}

	std::string Path::extension(const std::string &file)
	{
		std::size_t found = file.find_last_of(".");
		if(found == std::string::npos)
			return std::string("");
		else
			return file.substr(found+1, file.size());
	}
	std::string Path::extension(const char *file)
	{
		const std::string fileStr(file);
		return extension(fileStr);
	}

	namespace path
	{
		std::string docPath(const char *name, const char *ext)
		{
			Path &p = getPath();
			return p.docPath(name, ext);
		}
		std::string docPath(const char *file)
		{
			Path &p = getPath();
			return p.docPath(file);
		}
		std::string docPath(const std::string &file)
		{
			Path &p = getPath();
			return p.docPath(file);
		}

		std::string appPath(const char *name, const char *ext)
		{
			Path &p = getPath();
			return p.appPath(name, ext);
		}
		std::string appPath(const char *file)
		{
			Path &p = getPath();
			return p.appPath(file);
		}
		std::string appPath(const std::string &file)
		{
			Path &p = getPath();
			return p.appPath(file);
		}

		bool isFileExist(const std::string &file)
		{
			Path &p = getPath();
			return p.isFileExist(file);
		}
	}

}
